from django_redis import get_redis_connection
from django.shortcuts import HttpResponse
# 导入发送邮件的函数
from django.core.mail import send_mail


def set_redis(request):
    conn = get_redis_connection()
    conn.set('name','alice', ex=100)
    return HttpResponse("redis缓存成功！")


def get_redis(request):
    conn = get_redis_connection()
    result = conn.get('name')
    # 判断是否存在
    if result:
        return HttpResponse("redis:" + result.decode('utf-8'))
    else:
        return HttpResponse("缓存的数据不存在！")


def send_email(request):
    res = send_mail(
        "标题",  # 邮件标题
        "内容",  # 邮件正文
        '651205558@qq.com',  # 发送的邮箱
        recipient_list = ['13482034096@163.com'],  # 收件人的邮件
       )
    if res == 1:
        return HttpResponse("发送成功！")